//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __CWIN32SOCKET_H__
#define __CWIN32SOCKET_H__

#define _NO_CWIN32SOCKET_CLASSOBJECT_
#include "_CWin32Socket.h"
//#include <elatypes.h>
#include <car.h>
#include "Win32Socket.h"

#define STATUS_WIN32_ERROR(u) ((ECode)((u)|0x80070000))

#ifndef E_NOT_ENOUGH_MEMORY
#define E_NOT_ENOUGH_MEMORY       STATUS_WIN32_ERROR(   8)
#endif


CarClass(CWin32Socket)
{
public:
    CARAPI_(PInterface) Probe(
            /* [in] */ REIID riid);

    CARAPI_(UInt32) AddRef(void);

    CARAPI_(UInt32) Release(void);

    CARAPI Accept(
        /* [out] */ ISocket ** ppIncomingConnection,
        /* [out] */ SocketAddr* pAddress,
        /* [out] */ Int32 * pError);

    CARAPI Bind(
        /* [in] */ const SocketAddr & address,
        /* [out] */ Int32 * pError);

    CARAPI Connect(
        /* [in] */ const SocketAddr & address,
        /* [out] */ Int32 * pError);

    CARAPI GetPeerName(
        /* [out] */ SocketAddr* pAddress,
        /* [out] */ Int32 * pError);

    CARAPI GetSockName(
        /* [out] */ SocketAddr* pAddress,
        /* [out] */ Int32 * pError);

    CARAPI Listen(
        /* [in] */ Int32 backLog,
        /* [out] */ Int32 * pError);

    CARAPI Recv(
        /* [in] */ Flags32 flags,
        /* [in] */ Int32 bytesToRecv,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ Int32 * pError);

    CARAPI RecvFrom(
        /* [in] */ Flags32 flags,
        /* [in] */ Int32 bytesToRecv,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ SocketAddr* pSourceAddr,
        /* [out] */ Int32 * pError);

    CARAPI Send(
        /* [in] */ Flags32 flags,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesSent,
        /* [out] */ Int32 * pError);

    CARAPI SendTo(
        /* [in] */ Flags32 flags,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesSent,
        /* [in] */ const SocketAddr & targetAddr,
        /* [out] */ Int32 * pError);

    CARAPI Shutdown(
        /* [in] */ Int32 how,
        /* [out] */ Int32 * pError);

    CARAPI EventSelect(
        /* [in] */ IEvent * pEvent,
        /* [in] */ Int32 eventMask);

    CARAPI SetSockOpt(
        /* [in] */ Int32 level,
        /* [in] */ Int32 optName,
        /* [in] */ const MemoryBuf & optValue,
        /* [out] */ Int32 * pError);

    CARAPI GetSockOpt(
        /* [in] */ Int32 level,
        /* [in] */ Int32 optName,
        /* [in] */ Int32 optSize,
        /* [out] */ MemoryBuf * pOptValue,
        /* [out] */ Int32 * pError);

    CARAPI Ioctl(
        /* [in] */ Int32 command,
        /* [in] */ const MemoryBuf & inDataBuf,
        /* [out] */ MemoryBuf * pOutDataBuf,
        /* [out] */ Int32 * pError);

public:
    CWin32Socket(win32_socket so):m_Socket(so), m_cRef(0) 
    {};
    ~CWin32Socket();

private:
    // TODO: Add your private member variables here.
    CWin32Socket() {}

public:
    win32_socket m_Socket;
private:
    Int32 m_cRef;
};

#endif // __CWIN32SOCKET_H__
